var t = a(require("../../libs/mini/create")), e = a(require("../../store/index")), i = require("../../api/member");

function a(t) {
    return t && t.__esModule ? t : {
        default: t
    };
}

var n = getApp(), o = function(t) {
    return 0 == t ? "0.00" : (t = Number(t), isNaN(t) ? "0.00" : t = parseFloat(t.toFixed(2)));
};

t.default.Page(e.default, {
    use: [ "customLoading", "custom", "userInfo" ],
    data: {
        loading: !0,
        memberInfo: {},
        type: 0,
        cash: "",
        showMiniPopup: !1
    },
    onLoad: function(t) {},
    onShow: function() {
        var t = this;
        e.default.getCustom(function() {
            e.default.getUserInfo(function(e) {
                e = e.openid, (0, i.getMemberInfo)({
                    openid: e,
                    yesterday: 0
                }).then(function(e) {
                    e.cash = o(e.cash_remain - e.cash_today), t.setData({
                        loading: !1,
                        memberInfo: e
                    });
                }).catch(function() {
                    n.utils.modalText("获取成员信息失败，请检查是否有权限。").then(function() {
                        n.utils.alwaysBack();
                    });
                });
            });
        });
    },
    selectType: function(t) {
        t = t.currentTarget.dataset.type, this.setData({
            type: t
        });
    },
    handleShowPopup: function() {
        this.setData({
            showMiniPopup: !0
        });
    },
    handleCloseMiniPopup: function() {
        this.setData({
            showMiniPopup: !1
        });
    },
    onInputBlur: function(t) {
        if (t = t.detail, t = Number(t.value), isNaN(t)) return this.setData({
            cash: ""
        }), n.utils.toastText("金额格式输入错误");
        (t = parseFloat(t.toFixed(2))) ? this.setData({
            cash: t
        }) : this.setData({
            cash: ""
        });
    },
    handleDeposit: function() {
        var t = this;
        if (!this.loading) {
            var e = this.data.type, a = this.data.cash, s = this.data.memberInfo, u = s.openid, r = s.id, d = s.cash;
            return e ? 1 != e || s.image_wechat ? 2 != e || s.image_ali ? a ? d < (a = o(a)) ? n.utils.modalText("提现金额不能大于可提现金额") : a < 5 ? n.utils.toastText("提现金额不能低于5元") : (this.loading = !0, 
            wx.showLoading({
                title: "正在申请提现"
            }), void (0, i.generateDeposit)({
                type: e,
                cash: a,
                member_openid: u,
                member_id: r
            }).then(function() {
                t.loading = !1, wx.hideLoading(), n.utils.modalText("已申请提现，审核通过后将由平台根据您设置的收款渠道进行拨款。").then(function() {
                    s.cash_remain = o(s.cash_remain - a), t.setData({
                        memberInfo: s
                    }), wx.redirectTo({
                        url: "/pages/record/index"
                    });
                });
            }).catch(function(e) {
                t.loading = !1, wx.hideLoading(), console.error("ERROR: ", e), n.utils.modalText(e.message || "服务器出错，提现失败，请及时通知管理员。");
            })) : n.utils.toastText("请填写提现金额") : n.utils.modalText("检测到您还未上传支付宝收款码，请先上传你的支付宝收款码").then(function() {
                wx.navigateTo({
                    url: "/wifi/info/index"
                });
            }) : n.utils.modalText("检测到您还未上传微信收款码，请先上传你的微信收款码").then(function() {
                wx.navigateTo({
                    url: "/wifi/info/index"
                });
            }) : n.utils.toastText("请选择收款渠道");
        }
    },
    handleRecord: function() {
        wx.navigateTo({
            url: "/pages/record/index"
        });
    }
});